<?php
/**
 * ProjectName: Grapes.
 * Created by LemonZ.
 * FileName: Coupon.php
 * Date: 2019/2/14
 * Time: 15:42
 * Description:
 */

namespace app\admin\controller;


use app\common\controller\Admin;
use app\common\model\Coupon as CouponModel;
use think\facade\Request;

class Coupon extends Admin
{
    /**
     * @return mixed|void
     * @throws \think\exception\DbException
     */
    public function index()
    {
        $couponModel = new CouponModel();
        if (Request::isAjax())
        {
            return $couponModel->tableData(input('param.'));
        }
        if (!input('param.id')) {
            return $this->error('没有选择任何优惠券');
        } else {
            $this->assign('promotion_id', input('param.id'));
            return $this->fetch('');
        }
    }

    /**
     * 删除用户优惠券
     * @return array
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function  del()
    {
        $couponModel = new CouponModel();
        return $couponModel->del(input('param.coupon_code'));
    }
}